package AgendaGui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextArea;
import javax.swing.JTable;

public class AgendaGui extends JFrame {

	
	private Agenda agd = new Agenda(100);
	
	
	private JPanel contentPane;
	private JTextField txNomeContato;
	private JTextField txLogradouro;
	private JTextField txComplemento;
	private JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					AgendaGui frame = new AgendaGui();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public AgendaGui() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 947, 625);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		txNomeContato = new JTextField();
		txNomeContato.setBounds(225, 385, 86, 20);
		contentPane.add(txNomeContato);
		txNomeContato.setColumns(10);
		
		txLogradouro = new JTextField();
		txLogradouro.setColumns(10);
		txLogradouro.setBounds(225, 431, 86, 20);
		contentPane.add(txLogradouro);
		
		txComplemento = new JTextField();
		txComplemento.setColumns(10);
		txComplemento.setBounds(225, 474, 86, 20);
		contentPane.add(txComplemento);
		
		JLabel lblNome = new JLabel("Nome");
		lblNome.setBounds(97, 388, 46, 14);
		contentPane.add(lblNome);
		
		JLabel lblLoradouro = new JLabel("Logradouro");
		lblLoradouro.setBounds(97, 434, 98, 14);
		contentPane.add(lblLoradouro);
		
		JLabel lblComplemento = new JLabel("Complemento");
		lblComplemento.setBounds(97, 477, 98, 14);
		contentPane.add(lblComplemento);
		
		JButton btnAdicionatContato = new JButton("Adicionat contato");
		btnAdicionatContato.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nc = txNomeContato.getText();
				String lg = txLogradouro.getText();
				String cp = txComplemento.getText();
				
				Endereco end = new Endereco(nc, lg, cp);
				agd.iserirEndereco(end);
				
				
				
			}
		});
		btnAdicionatContato.setBounds(76, 530, 152, 23);
		contentPane.add(btnAdicionatContato);
		
		final JTextArea textArea = new JTextArea();
		textArea.setBounds(25, 11, 867, 293);
		contentPane.add(textArea);
		
		JButton btnExibirContatos = new JButton("Exibir contatos");
		btnExibirContatos.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				textArea.setText(agd.toString());
				table.toString();
			}
		});
		btnExibirContatos.setBounds(152, 314, 142, 23);
		contentPane.add(btnExibirContatos);
		
		table = new JTable();
		table.setBounds(422, 355, 470, 200);
		contentPane.add(table);
		
	}
}
